package com.dobbinsoft.iotechn.apigw;

import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.dobbinsoft.iotechn.data.annotaion.*;
import com.dobbinsoft.iotechn.data.logger.Logger;
import com.dobbinsoft.iotechn.data.logger.LoggerFactory;
import com.dobbinsoft.iotechn.device.IotechnDeviceApplication;
import com.dobbinsoft.iotechn.device.mqtt.IotMqttClient;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
import org.springframework.boot.autoconfigure.data.redis.RedisReactiveAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication(
		scanBasePackages = {
				"com.dobbinsoft.iotechn.apigw",
				"com.dobbinsoft.iotechn.user",
				"com.dobbinsoft.iotechn.device",
				"com.dobbinsoft.iotechn.ability"},
		exclude = {
				RedisAutoConfiguration.class,
				RedisReactiveAutoConfiguration.class,
				DruidDataSourceAutoConfigure.class
		})
@MapperScan({
		"com.dobbinsoft.iotechn.user.mapper*",
		"com.dobbinsoft.iotechn.device.mapper*"})
@EnableFrameworkDefaultMysql
@EnableFrameworkDefaultRedis
@EnableFrameworkDefaultOss
@EnableFrameworkSMSClient
@EnableFrameworkDefaultVod
@EnableFrameworkDefaultAdminNotify
public class FrameworkApigwApplication {

	private static final Logger logger = LoggerFactory.getLogger(IotechnDeviceApplication.class);

	public static void main(String[] args) {
		// 1. 初始化
		ConfigurableApplicationContext applicationContext = SpringApplication.run(FrameworkApigwApplication.class, args);
		// 2. 连接Broker
		IotMqttClient iotMqttClient = applicationContext.getBean(IotMqttClient.class);
		try {
			iotMqttClient.connect();
		} catch (Exception e) {
			logger.error("[连接Broker] 异常 请先启动Broker", e);
			System.exit(0);
		}
	}

}
